//
//  TranManagerCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/27.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "TranManagerCell.h"

@interface TranManagerCell ()

@property (nonatomic, strong) TranManagerMenuView *feiYongChaXunView;
@property (nonatomic, strong) TranManagerMenuView *kaiPiaoChaXunView;
@property (nonatomic, strong) TranManagerMenuView *yunFeiJieSuanView;
@property (nonatomic, strong) TranManagerMenuView *heTongView;
@property (nonatomic, strong) TranManagerMenuView *siJiView;
@property (nonatomic, strong) TranManagerMenuView *cheLiangView;

@end

@implementation TranManagerCell

+ (instancetype)TranManagerCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"TranManagerCell";
    TranManagerCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[TranManagerCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        CGFloat viewW = ScreenW * 0.333333;
        CGFloat viewH = 70;
        
        self.feiYongChaXunView = [[TranManagerMenuView alloc] initWithFrame:CGRectMake(0, 20, viewW, viewH)];
        self.feiYongChaXunView.iconUrl = @"Folder";
        self.feiYongChaXunView.titleStr = @"操作单费用查询";
        __weak_self;
        self.feiYongChaXunView.clickBlock = ^{
            if (weakself.feiYongChaXunBlock) {
                weakself.feiYongChaXunBlock();
            }
        };
        [self.contentView addSubview:self.feiYongChaXunView];
        
        self.kaiPiaoChaXunView = [[TranManagerMenuView alloc] initWithFrame:CGRectMake(self.feiYongChaXunView.nim_right, 20, viewW, viewH)];
        self.kaiPiaoChaXunView.iconUrl = @"Folder";
        self.kaiPiaoChaXunView.titleStr = @"开票查询";
        self.kaiPiaoChaXunView.clickBlock = ^{
            if (weakself.kaiPiaoChaXunBlock) {
                weakself.kaiPiaoChaXunBlock();
            }
        };
        [self.contentView addSubview:self.kaiPiaoChaXunView];
        
        self.yunFeiJieSuanView = [[TranManagerMenuView alloc] initWithFrame:CGRectMake(self.kaiPiaoChaXunView.nim_right, 20, viewW, viewH)];
        self.yunFeiJieSuanView.iconUrl = @"Folder";
        self.yunFeiJieSuanView.titleStr = @"运费结算";
        self.yunFeiJieSuanView.clickBlock = ^{
            if (weakself.yunFeiJieSuanBlock) {
                weakself.yunFeiJieSuanBlock();
            }
        };
        [self.contentView addSubview:self.yunFeiJieSuanView];
        
        self.heTongView = [[TranManagerMenuView alloc] initWithFrame:CGRectMake(0, 40 + self.feiYongChaXunView.nim_bottom, viewW, viewH)];
        self.heTongView.iconUrl = @"Folder";
        self.heTongView.titleStr = @"合同管理";
        self.heTongView.clickBlock = ^{
            if (weakself.heTongGuanLiBlock) {
                weakself.heTongGuanLiBlock();
            }
        };
        [self.contentView addSubview:self.heTongView];
        
        self.siJiView = [[TranManagerMenuView alloc] initWithFrame:CGRectMake(self.heTongView.nim_right, self.heTongView.nim_top, viewW, viewH)];
        self.siJiView.iconUrl = @"Folder";
        self.siJiView.titleStr = @"司机管理";
        self.siJiView.clickBlock = ^{
            if (weakself.siJiGuanLiBlock) {
                weakself.siJiGuanLiBlock();
            }
        };
        [self.contentView addSubview:self.siJiView];
        
        self.cheLiangView = [[TranManagerMenuView alloc] initWithFrame:CGRectMake(self.siJiView.nim_right, self.siJiView.nim_top, viewW, viewH)];
        self.cheLiangView.iconUrl = @"Folder";
        self.cheLiangView.titleStr = @"车辆管理";
        self.cheLiangView.clickBlock = ^{
            if (weakself.cheLiangGuanLiBlock) {
                weakself.cheLiangGuanLiBlock();
            }
        };
        [self.contentView addSubview:self.cheLiangView];
        
        self.height = self.cheLiangView.nim_bottom + 20;
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

@interface TranManagerMenuView ()

@property (nonatomic, strong) UIImageView *iconImgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIButton *clickBtn;

@end

@implementation TranManagerMenuView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {

        self.iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width - 40) * 0.5, 6, 40, 40)];
        [self addSubview:self.iconImgView];
        
        self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, self.iconImgView.nim_bottom + 9, frame.size.width, 15)];
        self.titleLab.textColor = HexColor(0x2B2C44);
        self.titleLab.font = [UIFont systemFontOfSize:14];
        self.titleLab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.titleLab];
        
        self.clickBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        [self.clickBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.clickBtn];
    }
    return self;
}

- (void)btnClick {
    if (self.clickBlock) {
        self.clickBlock();
    }
}

-(void)setIconUrl:(NSString *)iconUrl {
    _iconUrl = iconUrl;
    self.iconImgView.image = [UIImage imageNamed:iconUrl];
}

-(void)setTitleStr:(NSString *)titleStr {
    _titleStr = titleStr;
    self.titleLab.text = titleStr;
}

@end
